﻿using System;
using System.Collections.Generic;
using System.Text;

namespace iPdf
{
    partial class SessionsGrid
    {
        #region Columns

        #region ColumnHeads
        public class ColumnHead
        {
            public string Name;
            public int Index
            {
                get
                {
                    return Array.IndexOf(columnHeads, this);
                }
            }
            public int Width;

            public delegate void ColumnCreator(TataSession session);
            public ColumnCreator Creator;

            public ColumnHead(string name, int width, ColumnCreator creator)
            {
                Name = name;
                Width = width;
                Creator = creator;
            }

            public ColumnHead(string name, int width)
                : this(name, width, null)
            {
            }

            public ColumnHead(string name)
                : this(name, 0)
            {
            }


            public void Create(TataSession session)
            {
                if (Creator != null)
                {
                    Creator(session);
                }
            }
        }

        public static ColumnHead NameColumn = new ColumnHead("Name", 150);
        public static ColumnHead DescriptionColumn = new ColumnHead("Description", 165);
        public static ColumnHead[] columnHeads = new ColumnHead[] { NameColumn, DescriptionColumn };

        #endregion

        private SourceGrid.Cells.ColumnHeader CreateColumnHeader(object value)
        {
            SourceGrid.Cells.ColumnHeader colHeader = new SourceGrid.Cells.ColumnHeader(value);
            colHeader.View.Font = gridFont;
            return colHeader;
        }

        private void CreateColumn(ColumnHead column)
        {
            this[0, column.Index] = CreateColumnHeader(column.Name);
            if (column.Width > 0)
            {
                Columns[column.Index].Width = column.Width;
            }
        }

        #endregion
    }
}
